package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.entity.Article;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ArticleMapper extends BaseMapper<Article> {


    @Update("UPDATE articles SET views = views + 1 WHERE id = #{id}")
    void incrementViews(Integer id);

    @Select("SELECT * FROM articles WHERE user_id = #{userId}")
    List<Article> selectByUserId(@Param("userId") String userId);


    /**
     * 增加文章的评论数
     * @param id 文章ID
     * @return 影响的行数
     */
    @Update("UPDATE articles SET comment_count = comment_count + 1 WHERE id = #{id}")
    int incrementCommentCount(Integer id);
}
